﻿using HKB.Common;
using HKB.Web;
using HKB.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Admin_UpdateShop : Admin, IRequiresSessionState
{
    public int ShopID = 0;
    public string ErrMsg = "";
    private Shop_Shop _Shop_Shop = null;
    private Shop_Class _Shop_Class = null;
    private SkinBll _skin = null;
    protected DefaultProfile profile
    {
        get
        {
            return (DefaultProfile)this.Context.Profile;
        }
    }
    protected global_asax applicationInstance
    {
        get
        {
            return (global_asax)this.Context.ApplicationInstance;
        }
    }
    protected Shop_Shop m_Shop_Shop
    {
        get
        {
            Shop_Shop shop_Shop;
            if (this._Shop_Shop == null)
            {
                this._Shop_Shop = new Shop_Shop(this.conn);
                shop_Shop = this._Shop_Shop;
            }
            else
            {
                shop_Shop = this._Shop_Shop;
            }
            return shop_Shop;
        }
    }
    protected Shop_Class m_Shop_Class
    {
        get
        {
            Shop_Class shop_Class;
            if (this._Shop_Class == null)
            {
                this._Shop_Class = new Shop_Class(this.conn);
                shop_Class = this._Shop_Class;
            }
            else
            {
                shop_Class = this._Shop_Class;
            }
            return shop_Class;
        }
    }
    protected SkinBll m_skin
    {
        get
        {
            SkinBll skin;
            if (this._skin == null)
            {
                this._skin = new SkinBll(this.conn);
                skin = this._skin;
            }
            else
            {
                skin = this._skin;
            }
            return skin;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        this.LabCloseDate.Attributes.Add("onClick", string.Concat(new string[]
		{
			"show_cele_date(",
			this.LabCloseDate.UniqueID,
			",'','',",
			this.LabCloseDate.UniqueID,
			");"
		}));
        if (!base.admin.CheckAdminPower(17))
        {
            base.WriteLog("Modidy", Language.GetAdminMsg("Log/Access", "0"), "Shop");
            base.WriteRightErrMsg();
        }
        this.ShopID = Fetch.GetID("ShopID");
        if (this.ShopID != 0)
        {
            this.UpdateButton.Enabled = (this.DropIdentity.Enabled = (this.DropShopStatus.Enabled = true));
        }
        else
        {
            this.UpdateButton.Enabled = (this.DropIdentity.Enabled = (this.DropShopStatus.Enabled = false));
        }
        if (!base.IsPostBack)
        {
            this.DataBandShopList();
            this.BandShopGroup();
        }
    }
    protected void BandShopGroup()
    {
        ShopGroupBll shopGroupBll = new ShopGroupBll(this.conn);
        this.DrpShopLevel.DataSource = shopGroupBll.GetGroups();
        this.DrpShopLevel.DataBind();
    }
    private string getcssname(string str)
    {
        string result;
        if (str == "" || !str.Contains(".") || !str.Contains("/"))
        {
            result = string.Empty;
        }
        else
        {
            str = str.Remove(str.LastIndexOf('.'));
            str = str.Substring(str.LastIndexOf('/') + 1);
            result = str;
        }
        return result;
    }
    protected void DataBandShopList()
    {
        if (this.ShopID > 0)
        {
            DataTable shopByShopID = this.m_Shop_Shop.GetShopByShopID(this.ShopID);
            if (shopByShopID.Rows.Count >= 1)
            {
                DataTable proSkinBySkinType = this.m_skin.GetProSkinBySkinType("Shop");
                for (int i = 0; i < proSkinBySkinType.Rows.Count; i++)
                {
                    string text = this.getcssname(proSkinBySkinType.Rows[i]["SkinPath"].ToString());
                    if (text != string.Empty)
                    {
                        ListItem item = new ListItem(proSkinBySkinType.Rows[i]["SkinName"].ToString(), text);
                        this.DropShopSkin.Items.Add(item);
                    }
                }
                proSkinBySkinType.Dispose();
                this.DropShopClass.DataSource = this.m_Shop_Class.GetRootClass();
                this.DropShopClass.DataBind();
                DataRow dataRow = shopByShopID.Rows[0];
                this.LabShopAdUrl.Text = dataRow["ShopAdUrl"].ToString();
                DateTime dateTime = Convert.ToDateTime(dataRow["ShopCloseDate"].ToString());
                this.LabCloseDate.Text = string.Concat(new object[]
				{
					dateTime.Year,
					"-",
					dateTime.Month,
					"-",
					dateTime.Day
				});
                this.LabCredit.Text = dataRow["ShopCredit"].ToString();
                this.LabShopAnnouncement.Text = dataRow["ShopAnnouncement"].ToString();
                this.LabShopClick.Text = dataRow["ShopClick"].ToString();
                this.LabShopHelp.Text = dataRow["ShopHelp"].ToString();
                this.LabShopIntro.Text = dataRow["ShopIntro"].ToString();
                this.LabShopName.Text = dataRow["ShopName"].ToString();
                this.LabShopUrl.Text = dataRow["ShopURL"].ToString();
                this.LabU_NickName.Text = dataRow["ShopOwnerName"].ToString();
                this.DropIdentity.SelectedValue = dataRow["ShopIdentify"].ToString();
                this.DropShopClass.SelectedIndex = this.DropShopClass.Items.IndexOf(this.DropShopClass.Items.FindByValue(dataRow["ShopCategoryID"].ToString()));
                this.DropShopStatus.SelectedValue = dataRow["ShopStatus"].ToString();
                this.LabShopAddress.Text = dataRow["ShopAddress"].ToString();
                this.ProvinceCity.SelectedProvince = dataRow["Province"].ToString();
                this.ProvinceCity.SelectedCity = dataRow["City"].ToString();
                this.ProvinceCity.SelectedArea = dataRow["Area"].ToString();
                this.LabLastTimeLogin.Text = dataRow["LastTimeLogin"].ToString();
                this.LabShopOperatorItem.Text = dataRow["ShopOperatorItem"].ToString();
                bool @checked = false;
                if (dataRow["RecommendShop"].ToString() == "1" || dataRow["RecommendShop"].ToString().ToLower() == "true")
                {
                    @checked = true;
                }
                this.LabUserID.Text = dataRow["ShopOwnerID"].ToString();
                this.CheckRecommendShop.Checked = @checked;
                this.DropShopSkin.SelectedValue = dataRow["ShopStyle"].ToString();
                string imageUrl = dataRow["ShopImageUrl"].ToString();
                this.ImageShopImage.ImageUrl = imageUrl;
                if (dataRow["IsTax"].ToString() == "1" || dataRow["IsTax"].ToString().ToLower() == "true")
                {
                    this.DrpIsTax.Checked = true;
                }
                this.TxtTax.Text = dataRow["Tax"].ToString();
                this.DrpShopLevel.SelectedValue = dataRow["ShopGroupID"].ToString();
                this.LabShopRegDate.Text = dataRow["ShopRegDate"].ToString();
                this.LabIdentily.Text = this.DropIdentity.SelectedValue;
                int num = this.conn.ExecuteCount("Select count(*) From HLShop_Product Where ShopID=" + this.ShopID);
                this.TxtShopProductNums.Text = num.ToString();
            }
        }
    }
    protected void SendEmailToUser()
    {
    }
    protected void UpdateButton_Click(object sender, EventArgs e)
    {
        if (this.CheckParam())
        {
            DateTime shopCloseDate = DateTime.Now;
            DateTime lastTimeLogin = DateTime.Now;
            DateTime shopRegDate = DateTime.Now;
            int shopClick = 0;
            double tax = 0.0;
            if (!string.IsNullOrEmpty(this.LabCloseDate.Text))
            {
                shopCloseDate = Convert.ToDateTime(this.LabCloseDate.Text);
            }
            if (!string.IsNullOrEmpty(this.LabLastTimeLogin.Text))
            {
                lastTimeLogin = Convert.ToDateTime(this.LabLastTimeLogin.Text);
            }
            if (!string.IsNullOrEmpty(this.LabShopRegDate.Text))
            {
                shopRegDate = Convert.ToDateTime(this.LabShopRegDate.Text);
            }
            if (!string.IsNullOrEmpty(this.LabShopClick.Text))
            {
                shopClick = int.Parse(this.LabShopClick.Text);
            }
            if (!string.IsNullOrEmpty(this.TxtTax.Text))
            {
                tax = double.Parse(this.TxtTax.Text);
            }
            string selectedProvince = this.ProvinceCity.SelectedProvince;
            string selectedCity = this.ProvinceCity.SelectedCity;
            string area = "";
            if (this.ProvinceCity.SelectedArea != "")
            {
                area = this.ProvinceCity.SelectedArea;
            }
            string text = this.LabShopName.Text;
            string text2 = this.LabShopAdUrl.Text;
            string text3 = this.LabShopHelp.Text;
            string text4 = this.LabShopIntro.Text;
            string text5 = this.LabShopUrl.Text;
            string text6 = this.LabU_NickName.Text;
            string text7 = this.LabShopAddress.Text;
            string text8 = this.LabShopOperatorItem.Text;
            string text9 = this.LabShopAnnouncement.Text;
            string text10 = this.UploadImg();
            if (text10 == string.Empty)
            {
                text10 = this.ImageShopImage.ImageUrl;
            }
            string selectedValue = this.DropShopSkin.SelectedValue;
            string text11 = this.DropShopTem.Text;
            int shopIdentify = int.Parse(this.DropIdentity.SelectedValue);
            int shopCateGoryID = int.Parse(this.DropShopClass.SelectedValue);
            int shopStatus = int.Parse(this.DropShopStatus.SelectedValue);
            int shopGroupID = int.Parse(this.DrpShopLevel.SelectedValue);
            bool @checked = this.CheckRecommendShop.Checked;
            bool checked2 = this.DrpIsTax.Checked;
            int shopCredit = 0;
            int.TryParse(this.LabCredit.Text, out shopCredit);
            if (this.m_Shop_Shop.UpdateShop(text, text9, text4, shopCateGoryID, text10, text8, this.ShopID, text7, shopStatus, @checked, lastTimeLogin, text2, text6, shopClick, shopCloseDate, text3, shopIdentify, shopRegDate, selectedValue, text11, text5, checked2, tax, shopGroupID, shopCredit, selectedProvince, selectedCity, area))
            {
                base.WriteLog("Modify", Language.GetAdminMsg("Log/ObjectID", this.ShopID.ToString()), "Shop");
                this.WriteSuccessMsg("", Language.GetAdminMsg("Common/EditSuccess"), "?ShopID=" + this.ShopID);
            }
            else
            {
                this.WriteErrMsg("", Language.GetAdminMsg("Common/EditFail", "未知"), "");
            }
        }
        else
        {
            this.WriteErrMsg("", Language.GetAdminMsg("Common/ParamErr"), "");
        }
    }
    protected bool CheckParam()
    {
        return true;
    }
    public string UploadImg()
    {
        string result;
        if (this.FileUpload1.HasFile)
        {
            result = new UpLoadFile
            {
                SaveInFoder = "/UpLoadFile/UserShop/"
            }.UploadPic(this.FileUpload1, this.config, "");
        }
        else
        {
            result = "";
        }
        return result;
    }
}
